# -*- coding: utf-8 -*-
# python3.6

import json

import requests

cookies = {
    'EGG_SESS': 'qmz_emqN-0As7Rsp_4VJ4GTDXOsf3PBEZKJDCqS80ML_KIUcxNwqmBFAfsBxAQXn',
}


def Login(url, cookies):
    headers = {
        'Host': 'wanda.ffan.com',
        'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.1.2 Safari/605.1.15',
        'code': '1000769',
        'Referer': 'http://center.beyonds.com/',
        'Origin	': 'http://center.beyonds.com/',
        'Content-Length': '74',
        'orgTypeCode': '10003',
        'tenantId': '2017092600001',
        'token': 'MjI5MDEyNTI0MDQ4MDU2MzIw',
        'orgcode': '1000769',
        'Accept-Language': 'zh-cn',
        'workingOrgCode': '1000769',
        'orgname': '%E6%B8%A9%E5%B7%9E%E5%B9%B3%E9%98%B3%E4%B8%87%E8%BE%BE%E5%B9%BF%E5%9C%BA',
        'Accept': 'application/json, text/plain, */*',
        'Content-Type': 'application/json;chartset=utf-8',
        'Accept-Encoding': 'gzip, deflate',
    }

    data = '{"userName":"adminwzpy","password":"0659c7992e268962384eb17fafe88364","channel":0,"type":0}'
    Result = requests.post(url=url, headers=headers, cookies=cookies, data=data).text
    return Result


def checkNum(token, cookies, Uurl, phoneNum):
    headerA = {
        'Host': 'center.beyonds.com',
        'orgname': '%E6%B8%A9%E5%B7%9E%E5%B9%B3%E9%98%B3%E4%B8%87%E8%BE%BE%E5%B9%BF%E5%9C%BA',
        'plazaCode': '1000769',
        'orgTypeName': '%E5%B9%BF%E5%9C%BA',
        'userid': '259357274605461504',
        'orgcode': '1000769',
        'orgTypeCode': '10003',
        'workingOrgCode': '1000769',
        'areaCode': '10006',
        'groupCode': '101',
        'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36',
        'tenantId': '2018092600001',
        'Accept': 'application/json, text/plain, */*',
        'username': '%E6%B8%A9%E5%B7%9E%E5%B9%B3%E9%98%B3%E4%B8%87%E8%BE%BE%E5%B9%BF%E5%9C%BA%E7%AE%A1%E7%90%86%E5%91%98',
        'centerCode': '1007',
        'token': token,
        'Referer': 'http://center.beyonds.com/',
        'Accept-Encoding': 'gzip, deflate',
        'Accept-Language': 'zh-CN,zh;q=0.9',
        'Connection': 'keep-alive',
    }
    paramsA = {
        'pageIndex': '1',
        'pageSize': '10',
        'scope': 'DQFquanjituan',
        'scopeType': '10001',
        'mobileNo': phoneNum,

    }

    response = requests.get(url=Uurl, headers=headerA, params=paramsA, cookies=cookies).text
    return response


def chk(mobile):
    Uurl = 'http://center.beyonds.com/member/members?'
    # url = 'http://center.beyonds.com/permission/voyager/basisb/v1/user/login'
    # result = json.loads(Login(url, cookies))
    # print(result)
    token = "MjczNzUyMjgzMDUzMDIzMjMy"
    # print('token:\n' + token)
    result = json.loads(checkNum(token, cookies, Uurl, mobile))
    # print(result)
    count = result['data']['totalCount']
    if count == 0:
        return mobile
    else:
        return ""


if __name__ == '__main__':
    print(chk('13282053134'))
